package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.params.CounterGoodsParams;
import com.ruoyi.system.domain.params.SaveCounterGoodsGoodsParams;
import com.ruoyi.system.domain.vo.CounterGoodsListVo;
import com.ruoyi.system.service.IWhCounterGoodsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 货柜Controller
 *
 * @author ruoyi
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/system/counter/goods")
public class WhCounterGoodsController extends BaseController {
    @Resource
    private IWhCounterGoodsService counterGoodsService;

    /**
     * 查询货柜列表
     */
    @PreAuthorize("@ss.hasPermi('system:counter:list')")
    @GetMapping("/list")
    public AjaxResult list(CounterGoodsParams params) {
        return success(counterGoodsService.findWhCounterGoodsList(params));
    }

    /**
     * 导出货柜货物列表
     */
    @PreAuthorize("@ss.hasPermi('system:counter:export')")
    @Log(title = "货柜货物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CounterGoodsParams params) {
        List<CounterGoodsListVo> list = counterGoodsService.findWhCounterGoodsList(params);
        ExcelUtil<CounterGoodsListVo> util = new ExcelUtil<CounterGoodsListVo>(CounterGoodsListVo.class);
        util.exportExcel(response, list, "货柜数据");
    }

    /**
     * 获取货柜货物详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:counter:query')")
    @GetMapping(value = "/edit/info/{id}")
    public AjaxResult getEditInfo(@PathVariable("id") Integer id) {
        return success(counterGoodsService.selectCounterGoodsEditInfo(id));
    }

    /**
     * 新增货柜货物
     */
    @PreAuthorize("@ss.hasPermi('system:counter:add')")
    @Log(title = "新增货柜货物", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaveCounterGoodsGoodsParams params) {
        params.setCreateBy(getUserId() + "");
        params.setCreateTime(new Date());
        return toAjax(counterGoodsService.saveWhCounterGoods(params));
    }

    /**
     * 修改货柜货物
     */
    @PreAuthorize("@ss.hasPermi('system:counter:edit')")
    @Log(title = "修改货柜货物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SaveCounterGoodsGoodsParams params) {
        params.setUpdateBy(getUserId() + "");
        params.setUpdateTime(new Date());
        return toAjax(counterGoodsService.updateWhCounterGoods(params));
    }

    /**
     * 删除货柜货物
     */
    @PreAuthorize("@ss.hasPermi('system:counter:remove')")
    @Log(title = "删除货柜货物", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(counterGoodsService.deleteWhCounterGoodsByIds(ids));
    }

}
